import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import vueJsx from "@vitejs/plugin-vue-jsx";
import dts from "vite-plugin-dts";
import { resolve } from "path";

// https://vite.dev/config/
export default defineConfig({
  server: {
    host: "0.0.0.0",
    proxy: {
      // 字符串简写写法
      "/api": {
        target: "http://localhost:8080",
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  plugins: [
    vue(),
    dts({
      tsconfigPath: "./tsconfig.node.json",
      // 这里定义了需要生成d.ts文件的目录，如果有多个目录，可以使用数组
      // include: ['./src/**/**.d.ts']
    }),
    vueJsx(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  build: {
    target: "es2015",
    minify: "terser",
    lib: {
      entry: resolve(__dirname, "./src/index"),
      name: "EasyElForm",
      fileName: "easy-el-form",
      cssFileName: "style", // 确保css输出为dist/style.css
      formats: ["umd", "es", "cjs"],
    },
    rollupOptions: {
      external: ["vue"], // 排除打包vue进入组件
      output: {
        globals: {
          vue: "Vue",
        },
      },
    },
    cssCodeSplit: false, // 合并css到一个文件
  },
});
